package logic

import (
	"context"
	"errors"
	"goods/models/redisinit"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInfoCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoCartLogic {
	return &InfoCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *InfoCartLogic) InfoCart(in *goods.InfoCartRequest) (*goods.InfoCartResponse, error) {
	// todo: add your logic here and delete this line
	info, err := redisinit.CartInfo(in.UsersId, in.GoodsId)
	if err != nil {
		logx.Error("查询特定商品信息失败")
		return nil, errors.New("查询特定商品信息失败")
	}
	return &goods.InfoCartResponse{
		Lists: info,
	}, nil
}
